package servlet.response;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-07-16
 * Time:23:10
 */
@WebServlet(name = "DownloadServlet", urlPatterns = "/downloadServlet")
public class DownloadServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*第一种重定向方式
        '/' 被浏览器解析,解析为/localhost/   和转发区别,转发是服务器解析'/',解析为/Servlet/
         */
        //resp.sendRedirect("/Servlet/newDownloadServlet");
        /*
        第二种重定向方式
        动态绑定服务器的Application Context(/Servlet)
         */
        resp.sendRedirect(this.getServletContext().getContextPath() + "/newDownloadServlet");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
